package cn.gjculture.shopping.api.dao;

import cn.gjculture.shopping.api.entity.CashCoupon;
import cn.gjculture.shopping.api.entity.CashCouponRecord;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CashCouponDao {

    @Insert("insert into cashcoupon(cashCouponId,cashSum,cashCouponName,applySum,startTime,endTime,insertTime,updateTime,authorId,withOther,艺术家投票Id,status) " +
            " values(#{cashCouponId},#{cashSum},#{cashCouponName},#{applySum},#{startTime},#{endTime},#{insertTime},#{updateTime},#{authorId},#{withOther},#{customerId},#{status})")
    int insert(CashCoupon cashCoupon);

    @Select("select * from cashcoupon")
    List<CashCoupon> query();

    @Select("select * from cashcoupon where cashCouponId=#{cashCouponId}")
    CashCoupon queryById(String cashCouponId);

    @Delete("delete from cashcoupon where cashCouponId=#{cashCouponId}")
    int delete(String cashCouponId);

    @Insert("insert into cashcouponrecord(cashCouponRecordId,orderId,cashCouponId,useTime) " +
            "values(#{cashCouponRecordId},#{orderId},#{cashCouponId},#{useTime}})")
    int insertRecord(CashCouponRecord cc);

    @Select("select * from cashcoupon where customerId=#{customerId}")
    List<CashCoupon> queryByCustomerId(String customerId);

    @Select("select a.cashCouponId,a.cashSum,a.cashCouponName,a.applySum,a.startTime,a.endTime,a.withOther,a.customerId,a.`status`,b.useTime " +
            "from cashcoupon a " +
            "LEFT JOIN cashcouponrecord b on a.cashCouponId=b.cashCouponId where orderId=#{orderId}")
    List<CashCoupon> queryRecordByOrderId(String orderId);
}
